package servlet;

import bean.CustomerBean;
import bean.WarehouseBean;
import util.JdbcUtil;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class WarehouseModifyServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
           doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int wid =Integer.parseInt(request.getParameter("wid"));
        String sql ="SELECT * FROM warehouse Where wid=?";
        try {
            PreparedStatement ps = JdbcUtil.getConnection().prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
            ps.setInt(1,wid);
            ResultSet set = ps.executeQuery();
            set.absolute(1);
            WarehouseBean wa = new WarehouseBean();
            wa.setWid(set.getInt(1));
            wa.setWname(set.getString(2));
            wa.setWperson(set.getString(3));
            wa.setAddrss(set.getString(4));
            wa.setStatics(set.getString(5));
            HttpSession session = request.getSession();
            session.setAttribute("wa",wa);
            request.getRequestDispatcher("warehousemodify.jsp").forward(request,response);
        }catch (Exception e) {
            e.printStackTrace();
        }


    }
}

